%%
clc
img = imread('ycl.jpg');
I = rgb2gray(img);
imshow(I);
Roberts = edge(I,'roberts');    %进行Roberts算子边缘检测，门限值采用matlab默认值
Sobel = edge(I,'prewitt');    %进行Prewitt算子边缘检测，门限值采用matlab默认值
Prewitt = edge(I,'sobel');      %进行Sobel算子边缘检测，门限值采用matlab默认值
LoG = edge(I,'Canny');      % Canny算子的检测比较优越，它可以减少小模板检测中边缘中断，有利于得到较完整的边缘。
figure,imshow(Roberts);
figure,imshow(Sobel);
figure,imshow(Prewitt); 
figure,imshow(LoG); 


%%
close all; clear; clc;
% 读取图像
J = imread('rice.png');

% 定义三种梯度算子
% robertsKernel = fspecial('roberts');
prewittKernel = fspecial('prewitt');
sobelKernel = fspecial('sobel');

% 使用imfilter应用不同算子进行锐化处理
% J_roberts = imfilter(double(J), robertsKernel, 'replicate');
J_prewitt = imfilter(double(J), prewittKernel, 'replicate');
J_sobel = imfilter(double(J), sobelKernel, 'replicate');

% 转换结果为uint8以适合显示
% J_roberts = mat2gray(J_roberts) * 255;
J_prewitt = mat2gray(J_prewitt) * 255;
J_sobel = mat2gray(J_sobel) * 255;
% J_roberts = uint8(J_roberts);
J_prewitt = uint8(J_prewitt);
J_sobel = uint8(J_sobel);

subplot(131);imshow(J);title('原始图像');
% subplot(2, 2, 2);
% imshow(J_roberts);
% title('Roberts锐化');

subplot(132);imshow(J_prewitt);title('Prewitt锐化');
subplot(133);imshow(J_sobel);title('Sobel锐化');
